import 'dart:ui';

import 'package:whale/helper/utils/util.dart';

class MeansModel {
  String? id;
  String? documentTitle;
  String? industryType;
  String? companyType;
  String? companyName;
  String? reportType;
  String? problemType;
  dynamic projectPrice;
  String? hasProblem;
  num? documentScore;
  String? riskLevel;
  String? publishTime;
  String? createTime;

  /// 0 textColor  1 backgroundColor
  List<Color> get riskColors {
    if (riskLevel == '高风险') {
      return const [Color(0xffE93232), Color(0xffFBEBE9)];
    }

    if (riskLevel == '低风险') {
      return const [Color(0xff228FFA), Color(0xffDBEDFF)];
    }

    if (riskLevel == '中风险') {
      return const [Color(0xffEB932F), Color(0xffFBEDD4)];
    }

    return const [Color(0xff57BB72), Color(0xffE2F2E7)];
  }

  MeansModel({
    this.id,
    this.documentTitle,
    this.industryType,
    this.companyType,
    this.companyName,
    this.reportType,
    this.problemType,
    this.projectPrice,
    this.hasProblem,
    this.documentScore,
    this.riskLevel,
    this.publishTime,
    this.createTime,
  });

  factory MeansModel.fromJson(Map<String, dynamic> json) {
    String riskLevel = json['riskLevel'].toString();
    if (riskLevel.length > 3) {
      riskLevel = riskLevel.substring(1, 4);
    }
    return MeansModel(
      id: json['id'] as String?,
      documentTitle: json['documentTitle'] as String?,
      industryType: json['industryType'] as String?,
      companyType: json['companyType'] as String?,
      companyName: json['companyName'] as String?,
      reportType: json['reportType'] as String?,
      problemType: json['problemType'] as String?,
      projectPrice: json['projectPrice'] as dynamic,
      hasProblem: json['hasProblem'] as String?,
      documentScore: numVal(json['documentScore']),
      riskLevel: riskLevel,
      publishTime: json['publishTime'] as String?,
      createTime: json['createTime'] as String?,
    );
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        'documentTitle': documentTitle,
        'industryType': industryType,
        'companyType': companyType,
        'companyName': companyName,
        'reportType': reportType,
        'problemType': problemType,
        'projectPrice': projectPrice,
        'hasProblem': hasProblem,
        'documentScore': documentScore,
        'riskLevel': riskLevel,
        'publishTime': publishTime,
        'createTime': createTime,
      };
}
